import {Address} from "src/constants"
import server from '../request'
function GetSmsCode(payload) {
    let uri = Address + 'tool/auth/code'
    return server.requestPromise({uri: uri, method: 'POST', body: payload})
}
function checkCode(payload) {
    let uri = Address + 'user/check/code'
    return server.requestPromise({uri: uri, method: 'POST', body: payload})
}
function checkMobile(payload) {
    let uri = Address + 'user/check/mobile'
    return server.requestPromise({uri: uri, method: 'POST', body: payload})
}
function updateMobile(payload) {
    let uri = Address + 'user/update/mobile'
    return server.requestPromise({uri: uri, method: 'POST', body: payload})
}
function Regist(payload) {
    let uri = Address + 'user/register'
    return server.requestPromise({uri: uri, method: 'POST', body: payload})
}
function Login(payload) {
    let uri = Address + 'user/login'
    return server.requestPromise({uri: uri, method: 'POST', body: payload})
}
function LoginOut(payload) {
    let uri = Address + 'user/logout'
    return server.requestPromise({uri: uri, method: 'POST', body: payload})
}
function findPassword(payload) {
    let uri = Address + 'user/forget/password'
    return server.requestPromise({uri: uri, method: 'POST', body: payload})
}
function fetchCurrentUserInfo(payload) {
    let uri = Address + 'user/current?' + server.getParams(payload)
    return server.requestPromise({uri: uri, method: 'GET'})
}
function auth(payload) {
    let uri = Address + 'user/realname/auth'
    return server.requestPromise({uri: uri, method: 'POST', body: payload})
}
function uploadIdentifyCardImage(payload) {
    let uri = Address + 'user/ocr/idcard'
    let form = new FormData()
    let path = payload.image.path
    let filename = path.substr(path.lastIndexOf('/') + 1)
    let file = {uri: path, type: 'multipart/form-data', name: filename}
    form.append('idcard_image', file)
    form.append('token', payload.token)
    form.append('type', payload.type)
    return server.requestUpload({uri: uri, form: form})
}
function uploadCardImage(payload) {
    let uri = Address + 'user/ocr/bank'
    let form = new FormData()
    let path = payload.image.path
    let filename = path.substr(path.lastIndexOf('/') + 1)
    let file = {uri: path, type: 'multipart/form-data', name: filename}
    form.append('bank_image', file)
    form.append('token', payload.token)
    return server.requestUpload({uri: uri, form: form})
}
function avatarUpdate(payload) {
    let uri = Address + 'user/update/avatar'
    let path = payload.image.path
    let form = new FormData()
    let filename = path.substr(path.lastIndexOf('/') + 1)
    let file = {uri: path, type: 'multipart/form-data', name: filename}
    form.append('image', file)
    form.append('token', payload.token)
    return server.requestUpload({uri: uri,method:'POST',form:form})
}

function userShareImage(payload) {
    let uri = Address + 'user/share/image?' + server.getParams(payload)
    return server.requestPromise({uri: uri, method: 'GET'})
}

function paymentConfig(payload) {
    let uri = Address + 'user/payment/config?' + server.getParams(payload)
    return server.requestPromise({uri: uri, method: 'GET'})
}

function getSystemVersion(payload) {
    let uri = Address + 'version?' + server.getParams(payload)
    return server.requestPromise({uri: uri, method: 'GET'})
}
function getPhoneInfo(payload) {
    let uri = Address + 'phone/info'
    return server.requestPromise({uri:uri,method:'POST',body:payload})
}

function resetPassword(payload) {
    let uri = Address + 'user/reset/password'
    return server.requestPromise({uri:uri,method:'POST',body:payload})
}
module.exports = {
    auth: auth,
    GetSmsCode: GetSmsCode,
    Regist: Regist,
    Login: Login,
    findPassword: findPassword,
    fetchCurrentUserInfo: fetchCurrentUserInfo,
    uploadIdentifyCardImage: uploadIdentifyCardImage,
    uploadCardImage: uploadCardImage,
    LoginOut:LoginOut,
    userShareImage:userShareImage,
    avatarUpdate:avatarUpdate,
    getSystemVersion:getSystemVersion,
    checkCode:checkCode,
    checkMobile:checkMobile,
    updateMobile:updateMobile,
    getPhoneInfo:getPhoneInfo,
    resetPassword:resetPassword,
    paymentConfig:paymentConfig
}
